import paramiko

def ssh_client():
    source_folder = input("请输入原始目录：")
    target_folder = input("请输入存放目录：")
    ratio = input("请输入缩放系数：")
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
    ssh.connect(
        hostname="192.168.1.82",
        port=22, 
        username="root", 
        password="DELL123dell")
    params = [
        "/home/冯洋洋/PythonEnvironment/RasterShapeEnv/bin/python",
        "/home/冯洋洋/PythonProjection/RasterShape/GetL1cRaster.py",
        f"--province {province}" * (province != ""),
        f"--tiles {tiles}" * (tiles != ""),
        f"--yearmonth {yearmonth}" * (yearmonth != ""),
        f"--bands {bands}" * (bands != ""),
    ]
    command = " ".join(params)
    shell = ssh.invoke_shell()
    shell.settimeout(900)
    shell.send('export LANG=en_US.UTF-8 \n') #解决错误的关键，编码问题
    shell.send('export LANGUAGE=en \n')
    shell.send(command+'\n')
    buff = ''
    while not buff.endswith('# '):
        out = shell.recv(1024)
        buff += out.decode('utf8')
        print(out.decode('utf8'))     
    # stdin,stdout,stderr = ssh.exec_command(command, bufsize=-1)
    #stdin  标准格式的输入，是一个写权限的文件对象
    #stdout 标准格式的输出，是一个读权限的文件对象
    #stderr 标准格式的错误，是一个写权限的文件对象
    # print(stdout.read().decode())
    ssh.close()
    return

if __name__ == "__main__":
    ssh_client()